package com.ang.hutool.excel.complexDemos;

import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.ang.hutool.excel.complexDemos.data.ClassModel;
import com.ang.hutool.excel.complexDemos.data.DataProvider;

import java.util.List;

/**
 * 合并单元格
 */
public class Test01 {
    public static void main(String[] args) {
        Test01 test = new Test01();
        test.test01();
    }

    public void test01(){
        List<ClassModel> classList = DataProvider.getClassListData();

        ExcelWriter writer = ExcelUtil.getWriter("d:/test01.xlsx");

        writer.addHeaderAlias("id","ID");
        writer.addHeaderAlias("className","班级名称");

        //表示只导出定义了别名的字段
        writer.setOnlyAlias(true);

        //跳过当前行
        writer.passCurrentRow();
        //跳过两行
        //writer.passRows(2);
        //合并3列
        writer.merge(3,"合并3列");
        //合并单元格，不加默认样式
        writer.merge(15,18,0,1,"合并15-18行",false);
        //合并20-25行
        writer.merge(20,25,0,0,"合并20-25行",true);
        //导出数据
        writer.write(classList,true);

        //关闭writer，释放内存
        writer.close();
    }
}
